package cate.game.rank.history;

import com.fasterxml.jackson.annotation.JsonIgnore;
import easy.java.dev.note.NoteField;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

@ToString
public class RankReachHistory {
    @NoteField(value = "达成记录, 按达成时间排序")
    public List<RankReachRecord> records;

    @NoteField(value = "排行榜id")
    public int rankId;

    @NoteField(value = "奖励Id")
    public int rewardId;

    public synchronized void addRecord(RankReachRecord record) {
        if (records == null) {
            records = new ArrayList<>();
        }
        records.add(record);
    }

    @JsonIgnore
    public boolean isFull() {
        return records != null && records.size() > 5;
    }

    public boolean existRecord(String roleUid) {
        return records != null && records.stream().anyMatch(e -> StringUtils.equals(e.uid, roleUid));
    }
}
